import requests
import json
import yaml
import re
from litemall_api import Litemall


class TestMall:

    def setup_class(self):
        self.litemall = Litemall()
        #登录
        r = self.litemall.login("anni", "123456")
        #获取商品id
        goods_id = self.litemall.search_list('3d', '1', '10', '0')
        self.goods_id = goods_id
        #获取规格
        productId = self.litemall.goods_detail(self.goods_id)
        self.productId = productId

        print("suite 数据初始化 setup_class()")

    def setup(self):

        print("case级别初始化 setup()")

    # def test_login(self):
    #     print('-------------')
    #     r = self.litemall.login("anni", "123456")
    #     assert r.status_code == 200
    #     # print(r.json())
    #     assert r.json()['errno'] == 0
    #     assert r.json()['data']['userInfo']['nickName'] == 'anni'

    def test_search_list(self):
        pass
        # assert r == '1064006'
        # assert r.status_code == 200
        # assert r.json()['errno'] == 0
        # goods_id = r.json()['data']['list'][0]['id']

    def test_goods_detail(self):
        pass

    def test_add_cart(self):
        r = self.litemall.add_cart(self.goods_id, self.productId)
        assert r.status_code == 200
        assert r.json()['errmsg'] == '成功'

    def test_cart_list(self):
        r = self.litemall.cart_list()
        assert r.status_code == 200
        s = r.text
        r = re.search(r"goodsCount", s)
        assert r is not None


    def teardown(self):
        print("case teardown()")


    def teardown_class(self):
        print("suite 数据清理 teardown_class()")






